package com.todaynews.ui.home.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import com.todaynews.ui.home.NewsListFragment;
import com.todaynews.model.model.Channel;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 频道的adapter
 */

public class ChannelPagerAdapter extends FragmentStatePagerAdapter {

    private List<Channel> channels;
    private List<NewsListFragment> fragments;

    public ChannelPagerAdapter(List<Channel> channelList, FragmentManager fm) {
        super(fm);
        channels = channelList != null ? channelList : new ArrayList<>();
    }

    public ChannelPagerAdapter(List<NewsListFragment> fragmentList, List<Channel> channelList, FragmentManager fm) {
        super(fm);
        fragments = fragmentList != null ? fragmentList : new ArrayList<>();
        channels = channelList != null ? channelList : new ArrayList<>();
    }

    @Override
    public Fragment getItem(int position) {
        return fragments != null ? fragments.get(position):null;
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return channels.get(position).getTitle();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}